import env from "./env"
import sitemap from "./static/sitemap"
const webpack = require('webpack')

export default {
	telemetry: false,
	// Global page headers: https://go.nuxtjs.dev/config-head
	head: {
		title: 'm-blog',
		htmlAttrs: {
			lang: 'zh-CN',
		},
		meta: [
			{ charset: 'utf-8' },
			{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
			{ hid: 'description', name: 'description', content: '' },
			{ name: 'format-detection', content: 'telephone=no' },
		],
		link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.png' }],
		script: [
			//{ src: "js/flexible.js", type: 'text/javascript', charset: 'utf-8' }
		]
	},

	router: {
		// 路由中间件
		middleware: 'stats',
		routeNameSplitter: '/',
		extendRoutes(routes) {
			// 捕获未知路由，然后统一跳转到根路由
			routes.push({
				path: '*',
				redirect: '/'

			})
		},
		scrollBehavior(to, from, savedPosition) {
			// 路由跳转，滚动条置顶
			return { x: 0, y: 0 }
		}
	},

	loading: '@/components/loading',

	// Global CSS: https://go.nuxtjs.dev/config-css
	css: [
		// '~/assets/main.css',
		'element-ui/lib/theme-chalk/index.css',
		'@/assets/iconfont/iconfont.css',
		'quill/dist/quill.snow.css',
		'quill/dist/quill.bubble.css',
		'quill/dist/quill.core.css'
	],

	// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
	plugins: [
		// '@/plugins/baidu',
		// '@/plugins/baidu_js_push', // 百度自动推送
		// '@/plugins/360_js_push', // 360自动推送
		{ src: '@/plugins/baidu', ssr: false },
		{ src: '@/plugins/baidu_js_push', ssr: false },
		{ src: '@/plugins/360_js_push', ssr: false },
		{ src: '@/plugins/google_analytics', ssr: false },
		// { src: '~plugins/vue-quill-editor.js', ssr: false},
		{ src: '@/plugins/element-ui', ssr: false },
		{ src: '@/plugins/vue-highlight', ssr: false },
		{ src: '@/plugins/dompurify_html', ssr: false },

		'@/plugins/global-components',
		'@/plugins/request.js',
		'@/plugins/apiObj.js',
		'@/plugins/func.js',
		'@/plugins/head.js',
		// '@/plugins/vue-scroll.js'
	],

	// Auto import components: https://go.nuxtjs.dev/config-components
	components: true,

	// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
	buildModules: [
		// https://go.nuxtjs.dev/eslint
		// '@nuxtjs/eslint-module',
		// https://go.nuxtjs.dev/stylelint
		// '@nuxtjs/stylelint-module',
	],

	// Modules: https://go.nuxtjs.dev/config-modules
	modules: [
		// https://go.nuxtjs.dev/axios
		'@nuxtjs/axios',
		'@nuxtjs/proxy',
		'@nuxtjs/sitemap',
		'@nuxtjs/markdownit'
	],
	markdownit: {
		runtime: true,
		preset: 'default',
		linkify: true,
		breaks: true,
		use: [
			'markdown-it-div',
			'markdown-it-attrs',
			'markdown-it-highlightjs',
			'markdown-it-mark',
			'markdown-it-deflist'
		]
	},
	// Axios module configuration: https://go.nuxtjs.dev/config-axios
	axios: {
		// Workaround to avoid enforcing hard-coded localhost:3000: https://github.com/nuxt-community/axios-module/issues/308
		timeout: 30000,// 超时时间
		baseurl: env[process.env.NODE_ENV].SERVER_URL,// baseurl
		prefix: '/api',// 配置请求接口前缀
		proxy: true,// 开启代理
	},
	proxy: {
		'/api': {
			target: env[process.env.NODE_ENV].SERVER_URL,
			pathRewrite: {
				'^/api': '/api',
			},
			changeOrigin: true
		}
	},
	// Build Configuration: https://go.nuxtjs.dev/config-build
	build: {
		// 提取css
		extractCSS: true,
		transpile: [/^element-ui/],
		plugins: [
			new webpack.ProvidePlugin({
				'$': 'jquery',
				// 'window.Quill': 'quill/dist/quill.js',
				// 'Quill': 'quill/dist/quill.js'
			})
		],
		extend(config, ctx) { },
		// vendor:['vue-quill-editor',]
		// postcss: [
		// 	require("postcss-px2rem")({
		// 		remUnit: 75
		// 	})
		// 	// require('autoprefixer')
		// ],
		vendor: ['axios'] // 为防止重复打包
	},
	env: {
		NODE_ENV: env[process.env.NODE_ENV].NODE_ENV,
		// 统一登录 process.env.authURL
		LOGIN_URL: env[process.env.NODE_ENV].LOGIN_URL,
		// 请求前缀
		BASE_PREFIX: env[process.env.NODE_ENV].BASE_PREFIX,
		// 请求服务器地址
		SERVER_URL: env[process.env.NODE_ENV].SERVER_URL,
		// 前端系统的端口
		SYSTEM_PORT: env[process.env.NODE_ENV].SYSTEM_PORT
	},
	server: {
		port: env[process.env.NODE_ENV].SYSTEM_PORT,     // default: 3000
		// host: '0.0.0.0' // default: localhost
	},
	sitemap
}
